<?php

class ItemController extends Controller
{
	public function actionIndex($id=''){

		$meta = Item::model()->findbyPk($id);
		
		$meta->viewcount = $meta['viewcount']+1;
		$meta->save();
		
		$category2 = $meta['category'];
		$category2 = Category::model()->findbyPk($category2);
		
		$category = $category2['parent'];
		$category = Category::model()->findbyPk($category);
		
		echo CHtml::tag('title',array(),Item::model()->title($meta['id']).CHtml::encode(Yii::app()->name))."\n";
		Yii::app()->clientScript->registerMetaTag(Item::model()->description($meta['id']), 'description');
		Yii::app()->clientScript->registerMetaTag(Item::model()->keywords($meta['id']), 'keywords');

		$this->breadcrumbs=array(
			$category['title']=>array('category/index', 'id'=>$category['id']),
			$category2['title']=>array('category/index', 'id'=>$category2['id']),
			$meta['title'],
		);

        $this->yiistoRender('index', array('item' => $meta, 'category2' => $category2, 'category' => $category));
	}
	
	function actionSingle($id){
		$meta = Item::model()->findbyPk($id);
		if($meta){
			$item = $meta;
		}
		$this->renderPartial('singleCategoryLoop', array('item' => $item));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}